package org.NooLab.docserver;

import org.NooLab.docobserver.structures.DocumentObserverIntf;
import org.NooLab.docserver.main.DocumentObserverApplicationEventIntf;

public class FileChange implements FileChangeIntf{


	String descriptiveLabel = "";
	int    changeCode = -1 ;
	String updatedFilename = "";
	String previousFilename = "";
	
	// ------------------------------------------------------------------------
	public FileChange(String description, String filename, String previousname) {
	
		descriptiveLabel = description;
		updatedFilename = filename ;
		previousFilename = previousname ;
		changeCode = getChangeCode( descriptiveLabel );
	}
	// ------------------------------------------------------------------------
	

	private int getChangeCode(String label) {
		int code = -1;
		
		if (label.toUpperCase().contentEquals("MOD")){ code = DocumentObserverIntf._FILE_CHANGE_MOD; } ; 
		if (label.toUpperCase().contentEquals("DEL")){ code = DocumentObserverIntf._FILE_CHANGE_DEL; } ; 
		if (label.toUpperCase().contentEquals("NEW")){ code = DocumentObserverIntf._FILE_CHANGE_NEW; } ; 
		if (label.toUpperCase().contentEquals("MOVE")){ code = DocumentObserverIntf._FILE_CHANGE_MOVE; } ; 
		if (label.toUpperCase().startsWith("REN")){ code = DocumentObserverIntf._FILE_CHANGE_RENAME; } ; 
		
		return code;
	}

	
	public String getDescriptiveLabel() {
		return descriptiveLabel;
	}

	public void setDescriptiveLabel(String descriptiveLabel) {
		this.descriptiveLabel = descriptiveLabel;
	}

	public int getChangeCode() {
		return changeCode;
	}

	public void setChangeCode(int changeCode) {
		this.changeCode = changeCode;
	}

	public String getUpdatedFilename() {
		return updatedFilename;
	}

	public void setUpdatedFilename(String updatedFilename) {
		this.updatedFilename = updatedFilename;
	}

	public String getPreviousFilename() {
		return previousFilename;
	}

	public void setPreviousFilename(String previousFilename) {
		this.previousFilename = previousFilename;
	}


	public void inform(DocumentObserverApplicationEventIntf _appCallback) {

		if (_appCallback!=null){
			_appCallback.setLastRecordedChange( this ) ;
		}

	}
	
}
